package com.weichen.studentgameexchange.comment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weichen.studentgameexchange.comment.entity.CommentReport;
import com.weichen.studentgameexchange.comment.entity.vo.AddCommentReportVo;
import com.weichen.studentgameexchange.comment.entity.vo.ReportVo;
import com.weichen.studentgameexchange.comment.service.ICommentReportService;
import com.weichen.studentgameexchange.common.common.Result;
import com.weichen.studentgameexchange.common.exception.ServiceException;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 惟尘
 * @since 2025-02-05
 */
@RestController
@RequestMapping("/comment/commentReport")
public class CommentReportController {

    @Autowired
    ICommentReportService commentReportService;

    /**
     * 用户新增评论举报信息
     * @param addCommentReportVo
     * @return
     */
    @Operation(summary = "用户新增评论举报信息")
    @PostMapping("/user/add")
    public Result userAdd(@RequestBody AddCommentReportVo addCommentReportVo){
        return commentReportService.userAdd(addCommentReportVo);
    }

    /**
     * 用户查看自己所有的举报接口
     * @param userId
     * @return
     */
    @Operation(summary = "用户查看自己所有的举报接口")
    @GetMapping ("/user/select/{userId}")
    public Result userSelect(@PathVariable("userId") Long userId){
        return commentReportService.userSelect(userId);
    }

/**
 * TODO 管理员-评论管理--举报评论
 */
    /**
     * 管理员分页查询评论信息
     *
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "管理员分页查询评论举报信息接口")
    @GetMapping("/admin/page")
    public Result adminPage(@RequestParam("keyword") String keyword,
                            @RequestParam(value = "page", defaultValue = "1") Integer page,
                            @RequestParam(value = "size", defaultValue = "5") Integer size) {
        Page<CommentReport> commentReportPage = commentReportService.adminPage(keyword, page, size);
        return Result.success(commentReportPage);
    }

    /**
     * 管理员查看单个评论审核日志
     * @param reportId
     * @return
     */
    @Operation(summary = "管理员查看单个评论审核日志接口")
    @GetMapping("/admin/selectOne/{reportId}")
    public Result adminSelectOne(@PathVariable("reportId") Long reportId){
        ReportVo reportVo = commentReportService.adminSelectOne(reportId);
        return Result.success(reportVo);
    }

    /**
     * 管理员修改评论审核状态
     * @param reportVo
     * @return
     */
    @Operation(summary = "管理员修改评论审核状态接口")
    @PutMapping("/admin/update")
    public Result adminUpadte(@RequestBody ReportVo reportVo){
        commentReportService.adminUpadte(reportVo);
        return Result.success();
    }


    /**
     * 管理员删除单个评论举报信息
     *
     * @param reportId
     * @return
     */
    @Operation(summary = "管理员删除单个评论举报信息接口")
    @DeleteMapping("/admin/delete/{reportId}")
    public Result adminDeleteOne(@PathVariable("reportId") Long reportId) {
        if (commentReportService.getById(reportId) == null)
            throw new ServiceException("举报信息不存在！");
        commentReportService.removeById(reportId);
        return Result.success();
    }

    /**
     * 管理员批量删除多个评论举报信息
     *
     * @return
     */
    @Operation(summary = "管理员批量删除多个评论举报信息接口")
    @DeleteMapping("/admin/delete/batch")
    public Result adminDeleteBatch(@RequestBody List<Long> reportIds) {
        reportIds.forEach(this::adminDeleteOne);
        return Result.success();
    }
}
